//
//  MyHuanKuan.m
//  digitalCurrency
//
//  Created by 小震GG on 2019/11/20.
//  Copyright © 2019 XinHuoKeJi. All rights reserved.
//

#import "MyHuanKuan.h"
#import "MyHuanKuanCell.h"
#import "TiQianJieVC.h"
@interface MyHuanKuan ()

@property (nonatomic, strong) NSMutableArray *dataArr;

@property (nonatomic, strong) UILabel *bianHaoLB;

@property (nonatomic, strong) UILabel *daiHuanLB;
@property (nonatomic, strong) UILabel *qiShuLB;
@property (nonatomic, strong) UILabel *shiJianLB;

@end

@implementation MyHuanKuan

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = tBgQianColor;
    self.viewTitle.text = LocalizationKey(@"我的还款");
        
    self.dataArr = [[NSMutableArray alloc]init];
    
    [self setTopView];
}

- (void)setTopView{
    UIView *topView = [[UIView alloc]init];
       [self.view addSubview:topView];
       [topView mas_makeConstraints:^(MASConstraintMaker *make) {
           make.left.equalTo(0);
           make.right.equalTo(0);
           make.top.equalTo(0);
           make.height.equalTo(40);
       }];
       topView.backgroundColor = [UIColor colorWithHexStr:@"#4200FF" alpha:0.1];
    
    self.bianHaoLB = [[UILabel alloc]init];
    [topView addSubview:self.bianHaoLB];
    [self.bianHaoLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(16);
        make.centerY.equalTo(0);
    }];
    self.bianHaoLB.font = kFont(14);
    self.bianHaoLB.textColor = tMainColor;
    self.bianHaoLB.text = [NSString stringWithFormat:@"%@123456789",LocalizationKey(@"贷款编号：")];
    
    SYButton *rightBtn = [[SYButton alloc]init];
    [topView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(-16);
        make.centerY.equalTo(0);
    }];
    [rightBtn setImage:ImageName(@"j_jieJu") forState:UIControlStateNormal];
    [rightBtn setTitle:LocalizationKey(@"查看借据") forState:UIControlStateNormal];
    [rightBtn setTitleColor:tMainColor forState:UIControlStateNormal];
    rightBtn.titleLabel.font = kFont(12);
    rightBtn.btnType = LEFT;
    
    UIView *contentView = [[UIView alloc]init];
    [self.view addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(16);
        make.right.equalTo(-16);
        make.height.equalTo(287);
        make.top.equalTo(60);
    }];
    contentView.layer.cornerRadius = 5.0;
    contentView.backgroundColor = [UIColor whiteColor];
    contentView.layer.cornerRadius = 6.0;
    contentView.layer.shadowColor = [UIColor colorWithHEX:@"6E6E6E"].CGColor;
    contentView.layer.shadowOffset = CGSizeMake(0, 0);
    contentView.layer.shadowOpacity = 0.15;
    
    UILabel *titleLB = [[UILabel alloc]init];
    [contentView addSubview:titleLB];
    [titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(40);
        make.centerX.equalTo(0);
    }];
    titleLB.textColor = tThreeColor;
    titleLB.font = kFont(16);
    titleLB.text = LocalizationKey(@"本期待还");
    
    self.daiHuanLB = [[UILabel alloc]init];
    [contentView addSubview:self.daiHuanLB];
    [self.daiHuanLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(0);
        make.top.equalTo(75);
    }];
    self.daiHuanLB.textColor = tThreeColor;
    self.daiHuanLB.font = kFontPF_Bold(36);
    self.daiHuanLB.text = @"00.00";
    
    
    UILabel *qiShuTitleLB = [[UILabel alloc]init];
    [contentView addSubview:qiShuTitleLB];
    [qiShuTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0);
        make.top.equalTo(141);
        make.width.equalTo((kWindowW-32)/2.0);
    }];
    qiShuTitleLB.textColor = tNineColor;
    qiShuTitleLB.font = kFont(14);
    qiShuTitleLB.text = LocalizationKey(@"期数");
    qiShuTitleLB.textAlignment = NSTextAlignmentCenter;
    
    self.qiShuLB = [[UILabel alloc]init];
    [contentView addSubview:self.qiShuLB];
    [self.qiShuLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(qiShuTitleLB);
        make.top.equalTo(qiShuTitleLB.mas_bottom).offset(17);
    }];
    self.qiShuLB.textColor = tSixColor;
    self.qiShuLB.font = kFont(17);
    self.qiShuLB.text = @"1/12";
    
    UILabel *shiJianTitleLB = [[UILabel alloc]init];
    [contentView addSubview:shiJianTitleLB];
    [shiJianTitleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(0);
        make.top.equalTo(141);
        make.width.equalTo((kWindowW-32)/2.0);
    }];
    shiJianTitleLB.textColor = tNineColor;
    shiJianTitleLB.font = kFont(14);
    shiJianTitleLB.text = LocalizationKey(@"最后还款日");
    shiJianTitleLB.textAlignment = NSTextAlignmentCenter;
    
    self.shiJianLB = [[UILabel alloc]init];
    [contentView addSubview:self.shiJianLB];
    [self.shiJianLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(shiJianTitleLB);
        make.top.equalTo(shiJianTitleLB.mas_bottom).offset(17);
    }];
    self.shiJianLB.textColor = tSixColor;
    self.shiJianLB.font = kFont(17);
    self.shiJianLB.text = @"2019-00-00";
    
    
    UIButton *tiQianBtn = [[UIButton alloc]init];
    [contentView addSubview:tiQianBtn];
    [tiQianBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(15);
        make.bottom.equalTo(-30);
        make.width.equalTo((kWindowW-32-45)/2.0);
        make.height.equalTo(40);
    }];
    [tiQianBtn setTitle:LocalizationKey(@"提前结清") forState:UIControlStateNormal];
    [tiQianBtn setTitleColor:tMainColor forState:UIControlStateNormal];
    tiQianBtn.titleLabel.font = kFont(17);
    tiQianBtn.backgroundColor = [UIColor whiteColor];
    tiQianBtn.layer.cornerRadius = 5.0;
    tiQianBtn.layer.borderColor = tMainColor.CGColor;
    tiQianBtn.layer.borderWidth = 0.5;
    [tiQianBtn addTarget:self action:@selector(tiQianBtnAct) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *benQiBtn = [[UIButton alloc]init];
    [contentView addSubview:benQiBtn];
    [benQiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(-15);
        make.bottom.equalTo(-30);
        make.width.equalTo((kWindowW-32-45)/2.0);
        make.height.equalTo(40);
    }];
    [benQiBtn setTitle:LocalizationKey(@"偿还本期") forState:UIControlStateNormal];
    [benQiBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    benQiBtn.titleLabel.font = kFont(17);
    benQiBtn.backgroundColor = tMainColor;
    benQiBtn.layer.cornerRadius = 5.0;
    benQiBtn.layer.borderColor = tMainColor.CGColor;
    benQiBtn.layer.borderWidth = 0.5;
    [benQiBtn addTarget:self action:@selector(benQiBtnAct) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.layer.cornerRadius = 5.0;
    self.tableView.layer.shadowColor = [UIColor colorWithHEX:@"6E6E6E"].CGColor;
    self.tableView.layer.shadowOffset = CGSizeMake(0, 0);
    self.tableView.layer.shadowOpacity = 0.15;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.frame = CGRectMake(16, 358, kWindowW-32, kWindowH-358-SafeAreaTopHeight);
    self.tableView.rowHeight = 54;
    self.tableView.tableFooterView = [UIView new];
    if (@available(iOS 11.0, *)){
        self.tableView.estimatedRowHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
        self.tableView.estimatedSectionFooterHeight = 0;//防止刷新指定行时，偏移量改变
    }
}

#pragma 提前结清
- (void)tiQianBtnAct{
    TiQianJieVC *VC = [[TiQianJieVC alloc]init];
    VC.isTiQianStr = @"1";
    [self.navigationController pushViewController:VC animated:YES];
}

#pragma 偿还本期
- (void)benQiBtnAct{
    TiQianJieVC *VC = [[TiQianJieVC alloc]init];
    VC.isTiQianStr = @"2";
    [self.navigationController pushViewController:VC animated:YES];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count+5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyHuanKuanCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"id"];
    if (cell == nil) {
        cell = [[MyHuanKuanCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"id"];
    }
//    if (indexPath.row == 0) {
        [cell upDataModel:[[NSDictionary alloc]init] indexInt:indexPath.row];
//    }
//    else{
//        [cell upDataModel:self.dataArr[indexPath.row - 1] indexInt:indexPath.row];
//    }
    
    return cell;
   
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
